# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: AlexWMF <alexxwmf@gmail.com>

_realname=libcdio
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.1.0
pkgrel=3
pkgdesc="GNU Compact Disc Input and Control Library (mingw-w64)"
arch=('any')
license=('GPL3')
url="https://www.gnu.org/software/libcdio/"
options=('staticlibs' 'strip')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config")
depends=("${MINGW_PACKAGE_PREFIX}-libiconv"
         "${MINGW_PACKAGE_PREFIX}-libcddb")
source=(https://ftp.gnu.org/gnu/libcdio/${_realname}-${pkgver}.tar.bz2{,.sig}
        libcdio-0.83-linking.patch)
sha256sums=('8550e9589dbd594bfac93b81ecf129b1dc9d0d51e90f9696f1b2f9b2af32712b'
            'SKIP'
            'd88186b2a11726fe5ef10853e0245996b55793552b14230d1f7ba5ee3c54f3ed')
validpgpkeys=('DAA63BC2582034A02B923D521A8DE5008275EC21')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -Np1 -i "${srcdir}/libcdio-0.83-linking.patch"
  autoreconf -fiv
}

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}" && cd "${srcdir}/build-${MINGW_CHOST}"
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --disable-vcd-info \
    --enable-cpp-progs \
    --enable-shared \
    --enable-static \
    --disable-rpath

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make -j1 DESTDIR="${pkgdir}" install

  sed -i "/LIBCDIO_SOURCE_PATH/s|.*|/* #undef LIBCDIO_SOURCE_PATH */|" \
    ${pkgdir}${MINGW_PREFIX}/include/cdio/cdio_config.h
}
